#include "object.h"
#include <stdlib.h>
#include <allegro5/allegro_opengl.h>

void avgdl_object_init(struct object *o) {
	o->vcount = 3;
	o->v = 0;
	o->c = 0;

	// Init identity matrix
	for (int i = 0; i < 16; i++) {
		if (i%5 == 0) {
			o->matrix[i] = 1;
		}
		else {
			o->matrix[i] = 0;
		}
	}
}

void avgdl_object_draw(struct object *o) {

	// Matrix
	glPushMatrix();
	glMultMatrixf(o->matrix);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, o->v);
	glColorPointer(3, GL_FLOAT, 0, o->c);
	glDrawArrays(GL_TRIANGLES, 0, o->vcount);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

	// Pop matrix
	glPopMatrix();
}

void avgdl_object_shape(struct object *o, float *v, float vcount) {
	o->vcount = vcount;
	o->v = v;
}

void avgdl_object_color(struct object *o, float *c) {
	o->c = c;
}

void avgdl_object_location(struct object *o, float x, float y, float z) {
	o->matrix[12] = x;
	o->matrix[13] = y;
	o->matrix[14] = z;
}
